﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.Shell;


namespace JSEnhancements.JSESettings
{
	[Guid(GuidList.guidJSESettingsOptionsPage)]
	[ComVisible(true)]
	public partial class OptionsPage : DialogPage
	{
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool AutoCollapseJSRegions { get; set; }
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool AutoCollapseJSComments { get; set; }
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool AutoCollapseJSBraces { get; set; }
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool AutoCollapseJSToDefinitions { get; set; }

		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool AutoCollapseCssRegions { get; set; }
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool AutoCollapseCssComments { get; set; }
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool AutoCollapseCssBraces { get; set; }

		private OptionsPageControl OptionsControl;

		/// <summary>
		/// Gets the window an instance of DialogPage that it uses as its user interface.
		/// </summary>
		/// <devdoc>
		/// The window this dialog page will use for its UI.
		/// This window handle must be constant, so if you are
		/// returning a Windows Forms control you must make sure
		/// it does not recreate its handle.  If the window object
		/// implements IComponent it will be sited by the 
		/// dialog page so it can get access to global services.
		/// </devdoc>
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		protected override IWin32Window Window
		{
			get
			{
				OptionsControl = new OptionsPageControl();
				OptionsControl.Location = new Point(0, 0);
				OptionsControl.OptionsPage = this;
				return OptionsControl;
			}
		}

		public OptionsPage(): base()
		{
			AutoCollapseJSRegions = true;
			AutoCollapseCssRegions = true;
		}


		public override void SaveSettingsToStorage()
		{
			OptionsControl.UpdateOptions();
			base.SaveSettingsToStorage();
		}
	}
}
